package vistas;
import java.awt.event.ActionEvent;
import java.util.Iterator;
import java.util.Vector;

import javax.swing.AbstractAction;
import javax.swing.JButton;

import javax.swing.JFrame;
import javax.swing.JTable;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;

import clases.Alumno;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class JDListado extends javax.swing.JDialog {
	private JButton jButton1;
	private AbstractAction abstractAction1;
	private JTable jTable1;

	/**
	* Auto-generated main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				JDListado inst = new JDListado(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public JDListado(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	public void generarListado(Vector<Alumno> _alumnos){
		System.out.println(_alumnos.size());
		DefaultTableModel _modelo = new DefaultTableModel();
		jTable1.setModel(_modelo);
		Vector<String> v = new Vector<String>();
		v.add("Cedula");
		v.add("Nombre");
		v.add("Apellido");
		v.add("Nota Final");
		_modelo.setColumnIdentifiers(v);
		for (Iterator iterator = _alumnos.iterator(); iterator.hasNext();) {
			Alumno alumno = (Alumno) iterator.next();
			v = new Vector<String>();
			v.add(alumno.get_cedula());
			v.add(alumno.get_nombre());
			v.add(alumno.get_apellido());
			if(alumno.get_notafinal()==0)
				v.add("No se ha evaluado");
			else
				v.add(""+alumno.get_notafinal());
			_modelo.addRow(v);
    	}
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				{
					jButton1 = new JButton();
					getContentPane().add(jButton1);
					jButton1.setText("jButton1");
					jButton1.setBounds(168, 285, 114, 22);
					jButton1.setAction(getAbstractAction1());
				}
				{
					TableModel jTable1Model = 
						new DefaultTableModel(
								new String[][] { { "One", "Two" }, { "Three", "Four" } },
								new String[] { "Column 1", "Column 2" });
					jTable1 = new JTable();
					getContentPane().add(jTable1);
					jTable1.setModel(jTable1Model);
					jTable1.setBounds(23, 20, 399, 253);
				}
			}
			this.setSize(452, 347);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	private AbstractAction getAbstractAction1() {
		if(abstractAction1 == null) {
			abstractAction1 = new AbstractAction("Volver", null) {
				public void actionPerformed(ActionEvent evt) {
					dispose();
				}
			};
		}
		return abstractAction1;
	}

}
